package com.ruoyi.gis.controller;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.gis.domain.GisLayer;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.gis.domain.GisLayerBase;
import com.ruoyi.gis.service.IGisLayerBaseService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 系统图层Controller
 *
 * @author rww
 * @date 2023-11-16
 */
@RestController
@RequestMapping("/gis/baseLayer")
public class GisLayerBaseController extends BaseController
{
    @Autowired
    private IGisLayerBaseService gisLayerBaseService;

    /**
     * 查询系统图层列表
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:list')")
    @GetMapping("/list")
    public TableDataInfo list(GisLayerBase gisLayerBase)
    {
        startPage();
        List<GisLayerBase> list = gisLayerBaseService.selectGisLayerBaseList(gisLayerBase);
        return getDataTable(list);
    }

    @GetMapping("/list/all/layer")
    public AjaxResult listAllLayer(HttpServletRequest request, GisLayerBase gisLayerBase)
    {
        List<GisLayerBase> list = gisLayerBaseService.selectGisLayerBaseList(gisLayerBase);
        return AjaxResult.success(list);
    }

    /**
     * 导出系统图层列表
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:export')")
    @Log(title = "系统图层", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GisLayerBase gisLayerBase)
    {
        List<GisLayerBase> list = gisLayerBaseService.selectGisLayerBaseList(gisLayerBase);
        ExcelUtil<GisLayerBase> util = new ExcelUtil<GisLayerBase>(GisLayerBase.class);
        util.exportExcel(response, list, "系统图层数据");
    }

    /**
     * 获取系统图层详细信息
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:query')")
    @GetMapping(value = "/{layerId}")
    public AjaxResult getInfo(@PathVariable("layerId") Long layerId)
    {
        return success(gisLayerBaseService.selectGisLayerBaseByLayerId(layerId));
    }

    /**
     * 新增系统图层
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:add')")
    @Log(title = "系统图层", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GisLayerBase gisLayerBase)
    {
        return toAjax(gisLayerBaseService.insertGisLayerBase(gisLayerBase));
    }

    /**
     * 修改系统图层
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:edit')")
    @Log(title = "系统图层", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GisLayerBase gisLayerBase)
    {
        return toAjax(gisLayerBaseService.updateGisLayerBase(gisLayerBase));
    }

    /**
     * 删除系统图层
     */
    @PreAuthorize("@ss.hasPermi('gis:baseLayer:remove')")
    @Log(title = "系统图层", businessType = BusinessType.DELETE)
	@DeleteMapping("/{layerIds}")
    public AjaxResult remove(@PathVariable Long[] layerIds)
    {
        return toAjax(gisLayerBaseService.deleteGisLayerBaseByLayerIds(layerIds));
    }
}
